package com.framework.web.bus.service;
import com.framework.core.util.StringUtil;
import com.framework.core.util.UUIDGenerator;
import com.framework.web.bus.domain.Cookbook;
import com.framework.web.bus.repository.CookbookRepository;
import com.framework.web.bus.repository.specifications.CookbookSpecs;
import com.framework.web.common.domain.BusinessConstants;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
* @Title: Service
* @Description: 业务层
* @author fusf
* @date 2016-09-04
* @version V1.0
*
*/
@Service
public class CookbookService {

@Autowired
private CookbookRepository  cookbookRepository;

/**
* 新增或者保存
* @param cookbook
* @return
*/
public void save(Cookbook cookbook)throws IOException{
        cookbookRepository.save(cookbook);
}

/**
* 删除(逻辑)
* @param id
*/
public void  delete(String id) {
    Cookbook cookbook = cookbookRepository.findOne(id);
    cookbook.setStatus(BusinessConstants.STATUS.remove);
    cookbookRepository.save(cookbook);
}
/**
* 根据id查询
* @param id
* @return
*/
public Cookbook findById(String id) {
    return cookbookRepository.findOne(id);
}


/**
* 分页查找
* @param cookbook
* @param pr
* @return
*/
public Page<Cookbook> getPageList(Cookbook cookbook, PageRequest pr) {
    Page<Cookbook> totalList = cookbookRepository.findAll(CookbookSpecs.pageQueryCookbook(cookbook), pr);
    return totalList;
}

public void setImg(String realPath, MultipartFile[] files,String id) throws IOException {
    Cookbook cookbook = cookbookRepository.findOne(id);
    InputStream inputStream = null;
    if(cookbook!=null){
        //保存文件到/WEB-INF/img/cookbook

    }
}

}
